/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ru.miit.elearning.hibernate.dao;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.hibernate.Session;

/**
 *
 * @author Cyclone
 */
public class WebLabUtil {

    public static String prepareExceptionRef(HttpSession session, Exception e) {
            if(session != null) {
                session.setAttribute("exception", e);
                session.setAttribute("currentTimeMillis", System.currentTimeMillis());
                return ": <a href=\"Exception\">технические подробности</a>";
            }
            return null;
    }

//    public static void catchException(Exception e, Session session, String message, String redirect, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        e.printStackTrace();
//        message += prepareExceptionRef(request.getSession(), e);
//        request.getSession().setAttribute("message", message);
//        request.getRequestDispatcher(redirect).forward(request, response);
//        WebLabUtil.rollbackTransaction(session);
//    }
//
//
//
//    public static org.hibernate.Session prepareTransaction() {
//        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
//        session.getTransaction().begin();
//        return session;
//    }
//
//    public static void commitTransaction(Session session) {
//        if (session != null && session.isOpen()) {
//                    session.getTransaction().commit();
//                }
//    }
//
//    public static void rollbackTransaction(Session session) {
//        if (session != null && session.isOpen()) {
//                session.getTransaction().rollback();
//            }
//    }
//
//    public static void closeTransaction(Session session) {
//        if (session != null && session.isOpen()) {
//                session.close();
//            }
//    }
}
